<?php echo CHtml::cssFile('assets/css/redmond/jquery-ui-1.8.5.custom.css'); ?>
<?php echo CHtml::scriptFile('assets/js/jquery-ui-1.8.5.custom.min.js'); ?>

<?php echo CHtml::scriptFile('assets/tiny_mce/tiny_mce.js'); ?>
<?php echo CHtml::scriptFile('assets/js/editor_tinymce.js'); ?>

<script type="text/javascript">
	tinymce_image("image");
	//tinymce_advanced("image");
	tinymce_advanced("full_desc");
</script>

<div class="content">
	<div class="content_i">
    <?php
		
        echo CHtml::beginForm(array($this->controller_id."/save","product_id"=>$row["id"], 
			"pcategory_id" => $pcategory_id, "page"=>$page),"post", array("id"=>"form_edit"));
			echo "<table cellpadding='3' cellspacing='0 border='0' width='100%'>";
				echo "<tr>";
					echo "<td width='700px'>";

						echo "<h2>";
							echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-info.png");
							echo " Thông tin sản phẩm";
						echo "</h2>";
		
						echo "<table cellpadding='3' cellspacing='0 border='0' width='100%'>";
							echo "<tr>";
								echo "<td>";
									echo "<strong>Danh mục:</strong>";
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
									$list_cat = array();
									$list_cat[0] = "-- Chuyên mục --";
									$acategories_parent = pcategory::model()->findAll(array(
										"condition"=>"parent_id = 0 AND enable = 1",
										"order"=>"`order` ASC"
									));
									if (!is_null($acategories_parent))
									{
										foreach($acategories_parent as $acat)
										{
											$list_cat[$acat["id"]] = $acat["name"];
											$children = $acat->sub_category(array(
												"condition" => "enable = 1"
											));
											
											if (count($children) > 0)
											{
												foreach($children as $child)
													$list_cat[$child["id"]] = "... ".$child["name"];
											}
										}
									}
									if ($row->id == 0)
										echo CHtml::dropDownList(
											"pcategory_id", 
											$pcategory_id,
											$list_cat
										);
									else
										echo CHtml::dropDownList(
											"pcategory_id", 
											$row["pcategory_id"], 
											$list_cat
										);
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
									echo "<strong>Tên sản phẩm:</strong>";
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
									echo CHtml::textField("name", $row["name"], 
										array('style'=>'width:99%'));
								echo "</td>";
							echo "</tr>";
							
							
							echo "<tr>";
								echo "<td>";
									echo "<div style='float:left; width:350px;'>";
										echo "<strong>Tóm tắt sản phẩm:</strong>";
									echo "</div>";
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
									echo "<div style='width:100%; float:left;'>";
										echo CHtml::textArea("short_desc", 
											$row["short_desc"], 
											array('style'=>"width:100%; height:80px; ", 
												"spellcheck"=>'false')
										);
									echo "</div>";
																
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
									echo "<div style='float:left; width:320px;'>";
										echo "<strong>Ảnh Thumbnail:</strong>";
									echo "</div>";
									
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
								
									echo "<div style='width:100%; float:left;'>";
										echo CHtml::textArea("image", $row["image"],
					 						array(
												'style'=>'width:100%; height:200px;',
												"spellcheck"=>'false'
											)
										);
									echo "</div>";
									
								echo "</td>";
							echo "</tr>";
							
							
							echo "<tr>";
								echo "<td>";
									echo "<strong>Nội dung:</strong>";
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td>";
									echo CHtml::textArea("full_desc", $row["full_desc"],
					 					array(
											'style'=>'width:100%; height:450px;',
											"spellcheck"=>'false')
										);
								echo "</td>";
							echo "</tr>";
							
						echo "</table>";
						
						
					echo "</td>";
					
					echo "<td width='5px'>";
					echo "</td>";
					////////////////////////////////////////////
					echo "<td valign='top'>";
						echo "<h2>";
							echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-info.png");
							echo " Thông tin khác";
						echo "</h2>";
						
						echo "<table cellpadding='3' cellspacing='0 border='0' width='100%'>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Dịch vụ ";
								echo "</td>";
								echo "<td>";
									$list_dichvu = array();
									$list_dichvu[0] = "-- Dịch vụ --";
									$dichvu_array = dichvu::model()->findAll(array(
										"condition" => "enable = 1"
									));
									
									foreach($dichvu_array as $dichvu)
									{
										$list_dichvu[$dichvu->id] = $dichvu->name;
									}
									
									echo CHtml::dropDownList(
										"dichvu_id", 
										$row->dichvu_id, 
										$list_dichvu
									);
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Quận Huyện";
								echo "</td>";
								echo "<td>";
									$list_quan = array();
									$list_quan[0] = "-- Quận Huyện--";
									$quan_array = quan::model()->findAll(array(
										"condition" => "enable = 1"
									));
									
									foreach($quan_array as $quan)
									{
										$list_quan[$quan->id] = $quan->name;
									}
									
									echo CHtml::dropDownList(
										"quan_id", 
										$row->quan_id, 
										$list_quan
									);
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Đơn giá (Text)";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("price", $row->price, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Đơn giá (Number)";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("price_number", $row->price_number, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Diện tích (m<sup>2</sup>)";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("dien_tich", $row->dien_tich, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Số Tầng";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("so_tang", $row->so_tang, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Số phòng";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("so_phong", $row->so_phong, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Phòng ngủ";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("so_phong_ngu", $row->so_phong_ngu, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Phòng Vệ sinh";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("so_phong_vesinh", $row->so_phong_vesinh, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Gara";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("gara", $row->gara, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label' width='130px'>";
									echo "Số lượt xem";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("views", $row->views, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Thứ tự";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("order", $row->order, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Ngày tạo";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("create_time", $row->create_time, 
										array("style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Ngày bắt đầu";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("start_date", $row->start_date, 
										array("class"=>"datepicker","style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Ngày kết thúc";
								echo "</td>";
								echo "<td>";
									echo CHtml::textField("end_date", $row->end_date, 
										array("class"=>"datepicker","style" => "width:220px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Bật / Tắt";
								echo "</td>";
								echo "<td>";
									$list_enable = array(
										0=> "Tắt",
										1=> "Bật"
									);
									echo CHtml::dropDownList(
										"enable", 
										$row->enable, 
										$list_enable,
										array("style" => "min-width:100px;")
									);
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Hiển thị Tóm tắt";
								echo "</td>";
								echo "<td>";
									$list_bool = array(
										0=> "Không",
										1=> "Có"
									);
									echo CHtml::dropDownList(
										"allow_show_summary", 
										$row->allow_show_summary, 
										$list_bool, 
										array("style" => "min-width:100px;")
									);
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Hiển thị #Xem";
								echo "</td>";
								echo "<td>";
									echo CHtml::dropDownList(
										"allow_show_views", 
										$row->allow_show_views, 
										$list_bool, 
										array("style" => "min-width:100px;")
									);
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Hiển thị Ngày viết";
								echo "</td>";
								echo "<td>";
									echo CHtml::dropDownList("allow_show_create_time", 
									$row->allow_show_create_time, $list_bool, 
										array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Hiển thị Người viết";
								echo "</td>";
								echo "<td>";
									echo CHtml::dropDownList("allow_show_create_user", 
									$row->allow_show_create_user, 
									$list_bool, array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Cho phép In";
								echo "</td>";
								echo "<td>";
									$list_print = array(
										0=> "Không",
										1=> "Có"
									);
									echo CHtml::dropDownList("allow_print", $row->allow_print, $list_print,
										array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Cho phép nhận xét";
								echo "</td>";
								echo "<td>";
									$list_comment = array(
										0=> "Không",
										1=> "Có"
									);
									echo CHtml::dropDownList("allow_comment", $row->allow_comment, 
										$list_comment,array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Chia sẻ Facebook";
								echo "</td>";
								echo "<td>";
									$list_share = array(
										0=> "Không",
										1=> "Có"
									);
									echo CHtml::dropDownList("allow_share_facebook", 
									$row->allow_share_facebook, $list_share,
									array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Chia sẻ Twitter";
								echo "</td>";
								echo "<td>";
									echo CHtml::dropDownList("allow_share_twitter", 
									$row->allow_share_twitter, $list_share,
									array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Chia sẻ Zing";
								echo "</td>";
								echo "<td>";
									echo CHtml::dropDownList("allow_share_zing", 
									$row->allow_share_zing, $list_share,
										array("style" => "min-width:100px;"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Meta description";
								echo "</td>";
								echo "<td>";
									echo CHtml::textArea("meta_description", $row->meta_description, 
										array("style" => "width:220px;", "spellcheck"=>"false"));
								echo "</td>";
							echo "</tr>";
							
							echo "<tr>";
								echo "<td class='label'>";
									echo "Meta Keywords";
								echo "</td>";
								echo "<td>";
									echo CHtml::textArea("meta_keywords", $row->meta_keywords, 
										array("style" => "width:220px;", "spellcheck"=>"false"));
								echo "</td>";
							echo "</tr>";
							
						echo "</table>";
					echo "</td>";
					///////////////////////////
				echo "</tr>";
				///////////////////////////
				echo "<tr>";
					echo "<td>";
						echo "<div class='space_5'></div>";

						echo 
							"<div class='button' id='button_submit'>" .
								"<div style='float:left; width:20px;'>" .
									CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-save.png") .
								"</div>" .
								"<div style='float:left; min-width:40px;font-weight:bold'>".
									"Save" .
								"</div>" .
							"</div>";
						
						echo 
							"<div class='button' id='button_cancel'>" .
								"<div style='float:left; width:20px;'>" .
									CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-check.png") .
								"</div>" .
								"<div style='float:left; min-width:50px;font-weight:bold'>".
									"Cancel" .
								"</div>" .
							"</div>";
							
					echo "</td>";
					
					echo "<td>";
					echo "</td>";
				echo "</tr>";
				
			echo "</table>";
		echo CHtml::endForm();
	?>
    </div>
</div><!-- end div right -->

<script language="javascript">
$(document).ready(function(){

	$('#button_submit').click(function(){
		$('#form_edit').submit();
	});
	
	$('#button_cancel').click(function(){
		window.location = '<?php
			$url = Yii::app()->createUrl(
				$this->route . "/view",
				array("pcategory_id"=>$pcategory_id, "page" => $page)
			);
			echo $url;
		?>';
	});
});
</script>